#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
const ll N = 2e5 + 10;
const ll mod = 998244353;
ll a[N];
ll n, m;
void solve()
{
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    ll cnt = 0, now = 0, ans = 0;
    for (int i = n; i >= 1; i--)
    {
        if (a[i] == 3)
        {
            cnt++;
            now++;
        }
        else if (a[i] == 1)
        {
            ans = (ans + now - cnt + mod) % mod;
        }
        else
        {
            now = now * 2 % mod;
        }
    }
    cout << ans << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
